/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2023/2/27 20:53
 * @Version 1.0
 */
package com.eight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eight.dao.CarConfigDao;
import com.eight.pojo.TbCarTypeConfigDetails;
import com.eight.service.CarConfigService;
import com.eight.vo.CarVo;
import com.eight.vo.ComResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarConfigServiceImpl implements CarConfigService {

    @Autowired
    private CarConfigDao carConfigDao;

    @Override
    public ComResult selectAllConfig(CarVo carVo) {
        Page<Object> page = PageHelper.startPage(carVo.getPageNum(), carVo.getPageSize());
        QueryWrapper<TbCarTypeConfigDetails> wrapper=null;
        if (carVo.getName() != null) {
            wrapper = new QueryWrapper<>();
            wrapper.like("typename",carVo.getName());
        }
        List<TbCarTypeConfigDetails> typeConfigDetails = carConfigDao.selectList(wrapper);
        PageInfo<TbCarTypeConfigDetails> pageInfo = new PageInfo<>(typeConfigDetails);
        return new ComResult(2000,"查询所有车辆的配置",pageInfo);

    }

    @Override
    public ComResult insertConfig(TbCarTypeConfigDetails tbCarTypeConfigDetails) {
        int insert = carConfigDao.insert(tbCarTypeConfigDetails);
        return new ComResult(2000,"添加车辆的配置",insert);
    }

    @Override
    public ComResult deleteConfig(int id) {
        int delete = carConfigDao.deleteById(id);
        return new ComResult(2000,"删除车辆的配置",delete);
    }

    @Override
    public ComResult updateConfig(TbCarTypeConfigDetails tbCarTypeConfigDetails) {
        int update = carConfigDao.updateById(tbCarTypeConfigDetails);
        return new ComResult(2000,"修改车辆的配置",update);
    }
}

